from flask import Blueprint, jsonify
from services.document_service import DocumentService

task_bp = Blueprint('task', __name__)
document_service = DocumentService()

@task_bp.route('/<task_id>', methods=['GET'])
def get_task_status(task_id):
    """
    获取任务进度
    
    Args:
        task_id (str): 任务ID
        
    Returns:
        JSON: 任务状态信息
            成功: {
                "status": str,  # 任务状态
                "progress": float,  # 进度百分比
                "error": str,  # 错误信息（如果有）
            }
            失败: {"error": "错误信息"}, 状态码
    """
    try:
        status = document_service.get_task_status(task_id)
        return jsonify(status)
    except Exception as e:
        return jsonify({"error": str(e)}), 400